package com.meals.system.api.system;

import com.meals.system.api.system.vo.WhitesMealIndexCategoryVO;
import com.meals.system.common.ServiceResultEnum;
import com.meals.system.common.SystemException;
import com.meals.system.service.WhitesMealSellerCategoryService;
import com.meals.system.util.Result;
import com.meals.system.util.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Description:
 * Parm:
 * return:
 * Author: Chen
 * Date: 2021/12/10
 */
@RestController
@Api(value = "v1", tags = "0-2.白餐系统商家分类页面接口")
@RequestMapping("/user-api/v1")
public class WhitesMealSystemSellerCategoryAPI {

    @Resource
    private WhitesMealSellerCategoryService whitesMealSellerCategoryService;

    @GetMapping("/categories")
    @ApiOperation(value = "获取分类数据", notes = "分类页面使用")
    public Result<List<WhitesMealIndexCategoryVO>> getCategories(){
        List<WhitesMealIndexCategoryVO> categoryVOS = whitesMealSellerCategoryService.getCategoriesForIndex();
        if (CollectionUtils.isEmpty(categoryVOS)){
            SystemException.fail(ServiceResultEnum.DATA_NOT_EXIST.getResult());
        }
        return ResultGenerator.genSuccessResult(categoryVOS);
    }
}
